home *** CD-ROM | disk | FTP | other *** search
- /*[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]*/
- /* UObject.p */
- /* Copyright © 1984-1990 Apple Computer, Inc. All rights reserved. */
- #ifndef __UObject__
- #define __UObject__ 0
- #endif
- #if ! __UObject__
- #define __UObject__ 1
-
- /* • Auto-Include the requirements for this unit's interface. */
- #ifndef __UMacAppUtilities__
- #include "UMacAppUtilities.h"
- #endif
- #ifndef __MEMORY__
- #include "Memory.h"
- #endif
-
- const short kFailNone = 1;
- const short kFailAbstract = 2;
- const short kFailCoercion = 3;
- const short kFailMethNotFound = 4;
-
- const unsigned char kInvalidObj[] = "\p*Not an object*";
- /* return value from LookupObjName if not an
- object*/
- const short kNilClass = 0;
- /* Value for superclass of the root object */
-
- typedef unsigned short ObjClassID; /* Object Class identifier. The first two
- bytes of each object contain the class of
- the object as an ObjClassID. */
- typedef ObjClassID *ObjClassIDPtr; /* Preferred */
- typedef ObjClassIDPtr *ObjClassIDHandle; /* Preferred */
- typedef ObjClassIDPtr PObjClassID; /* Left in for compatibility (2.0) */
- typedef ObjClassIDHandle HObjClassID; /* Left in for compatibility (2.0) */
-
- /*--------------------------------------------------------------------------------------
- ------------*/
- /* Definition of the system's root object */
-
-
- class TObject : public PascalObject {
- public:
- virtual pascal TObject *Clone(void);
-
- /* Makes a duplicate copy of SELF. The default calls SELF.ShallowClone, which makes a
- literal copy of instance variables but does not attempt to clone owned objects. A
- subclass which owns other objects should override this to clone the owned objects
- and data structures as well. */
-
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Calls DoToField once for each instance variable in SELF. fieldName is a string
- representing the name of the variable. fieldAddr is the address of that variable.
- fieldType is one of the types defined in UMacAppUtilities. It is legal to use a
- local variable to hold data and pass the address of that variable to DoToField as
- if it were part of the object's instance variables. By convention, the first call
- to DoToField should have the class name as the fieldName, NIL as the fieldAddr, and
- bClass as the fieldType. Each subclass should override this method, particularly
- with qDebug on, dump its own information, then call INHERITED. */
-
- virtual pascal void DynamicFields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- dynamic area. Defaults to nothing. Override if your object uses the dynamic area
- See TList for an example. */
-
- virtual pascal void ForAllSubClassesDo(pascal void (*DoToSubClass)(ObjClassID theClass, void *
- DoToSubClass_StaticLink), void *DoToSubClass_StaticLink);
-
- /* Calls DoToSubClass for each subclass of SELF. The order of traversal is arbitrary;
- see EachSubClass global procedure. */
-
- virtual pascal void ForAllSuperClassesDo(pascal void (*DoToSubClass)(ObjClassID theClass, void *
- DoToSubClass_StaticLink), void *DoToSubClass_StaticLink);
-
- /* Calls DoToSubClass for each superclass of SELF. The order of traversal is the order
- of ancestry starting from the class of SELF; see EachSuperClass global procedure. */
-
- virtual pascal void Free(void);
- /* Called to dispose of an object. Gives object a chance to cleanup after itself.
- Default simply calls SELF.ShallowFree, which makes no attempt to free instance
- variables. Should be overridden by any class which allocates space or owns other
- objects in its instance variables.. Be sure to call INHERITED! */
-
- virtual pascal ObjClassID GetClass(void);
- /* Returns the class ID of SELF. */
-
- virtual pascal void GetClassName(StringPtr clName);
- /* Returns the class name of SELF. */
-
- virtual pascal Size GetClassSize(void);
- /* Returns the basic instantiation size. i.e. the size in bytes of a newly created
- object of this class */
-
- virtual pascal Ptr GetDynamicPtr(void);
- /* Our objects have a dynamic area available. In 2.0 it is at the end of the object
- handle but it may not always be so. Returns a direct heap pointer to the start
- of the dynamic area. Use with caution as this pointer can be invalidated if the
- heap compacts. */
-
- virtual pascal Size GetDynamicSize(void);
- /* Our objects can have a dynamic area that can be allocated with a SetDynamicSize
- call. Returns the size of the dynamic area in bytes. Preferred. */
-
- virtual pascal Size GetInstanceSize(void);
- /* Our objects have a dynamic area after all the fixed fields. Returns the current
- size in bytes of this instance accounting for the dynamic area.
- Left in for compatibility (2.0) */
-
- virtual pascal ObjClassID GetSuperClass(void);
- /* Returns immediate superclass of class. Returns kNilClass for TObject. If we ever
- get MI this will have to be an enumerator. */
-
- virtual pascal void GetInspectorName(StringPtr inspectorName);
- /* Returns additional information useful to the inspector. For instance (ha ha!) a
- TDocument could give its title. */
-
- virtual pascal void Initialize(void);
- /* Call this to put a newly created object into a known state. Subclasses should
- override it and call INHERITED. Typically used to put the object into a state where
- it can be safely FREED. Defaults to nothing. */
-
- virtual pascal void Inspect(void);
- /* Called from the debugger. Displays the fields of the object in the writeln window
- by calling the object's Fields method, passing InspectField as the DoToField
- routine. You can override this if you want to display any additional information in
- the writeln window when an object is inspected with the MacApp debugger. NOTE: this
- is not currently called from the "Inspector".*/
-
- virtual pascal void IObject(void);
- /* The ancestral initializer. Should be called in the I<ClassName> chain. i.e. IView
- -> IEvtHandler -> IOBJECT */
-
- virtual pascal Boolean IsMemberClass(ObjClassID testClass);
- /* True if I am a MEMBER of the testClass. i.e. the same class OR a subclass. */
-
- virtual pascal Boolean IsSameClass(ObjClassID testClass);
- /* True if I belong to the immediate class. */
-
- virtual pascal Boolean Lock(Boolean lockIt);
- /* Locks down or unlocks an object AND its dynamic area if any. Returns old state.
- Since objects can float around in memory some occasions may arise where they need
- to be locked down (The Inspect method is an example: since addresses of instance
- variables are being passed, the object had better not move during the Inspect!)
- Typically the old state is saved in a local and re-applied when ascending the
- call chain. Don't forget to re-apply the old state from failure handlers.
- _PLEASE_ use this sparingly and don't just go locking stuff down willy-nilly just
- because you might be afraid of handles. */
-
- virtual pascal void SetDynamicSize(Size newSize);
- /* Set this instance's Dynamic Area size in bytes. The dynamic area starts out
- unallocated. Signals Failure on memory error. The size applies only to the size
- of the Dynamic Area. Preferred. */
-
- virtual pascal void SetInstanceSize(Size newSize);
- /* Set this instance's size in bytes. Thus changing the size of the dynamic area.
- Fails on attempts to set a size smaller than instantiation size and on memory
- error. Left in for compatibility (2.0) */
-
- virtual pascal TObject *ShallowClone(void);
-
- /* Lowest level method for copying an object; should not be overridden except in very
- unusual cases. Simply calls HandToHand to copy the object data. */
-
- virtual pascal void ShallowFree(void);
-
- /* Lowest level method for freeing an object; should not be overridden except in very
- unusual cases. Simply calls Dispose (the Pascal builtin) to free the object. */
-
- };
-
- typedef TObject **TObjectPtr; /* Preferred */
- typedef TObjectPtr *TObjectHandle; /* Preferred */
- typedef TObjectPtr PTObject; /* Left in for compatibility (2.0) */
- typedef TObjectHandle HTObject; /* Left in for compatibility (2.0) */
-
- /*--------------------------------------------------------------------------------------
- ------------*/
- /* Utility routines to support objects */
-
- extern pascal Boolean AddNewObjectsToInspector(Boolean add);
- /* Set to true (default) to automatically add all newly created objects to the inspector.
- Function returns old setting. */
-
- extern pascal Boolean AllocateObjectsFromPerm(Boolean allocateFromPerm);
- /* Set to TRUE to make object allocation calls use Permanent memory (the default).
- Set to false to make object allocation calls use temporary memory (if they cannot be
- allowed to fail). Returns old state */
-
- extern pascal Boolean DisciplineMethodCalls(Boolean discipline);
- /* Set to true to discipline all method calls that go through the dispatcher. Function r
- eturns
- old setting. */
-
- extern pascal void EachClassDo(pascal void (*DoToClass)(ObjClassID theClass, void *
- DoToClass_StaticLink), void *DoToClass_StaticLink);
- /* Calls DoToClass for each class in the application */
-
- extern pascal void EachSubClassDo(ObjClassID testClass, pascal void (*DoToClass)(ObjClassID theClass
- , void *DoToClass_StaticLink), void *DoToClass_StaticLink);
- /* Calls DoToClass for subclass of the test class. Uses EachClassDo, so the order of ite
- ration
- is not based on the class hierarchy but on the sequence of class IDs in the class table,
-
- Sorry… */
-
- extern pascal void EachSuperClassDo(ObjClassID testClass, pascal void (*DoToClass)(ObjClassID
- theClass, void *DoToClass_StaticLink), void *DoToClass_StaticLink);
- /* Calls DoToClass for superclass of the test class. Order of iteration is in order of
- ancestry. */
-
- extern pascal void FailNonObject(void *obj);
- /* called by dispatcher to discipline an object. Invokes failure if parameter is not IsO
- bject
- */
-
- extern pascal void FreeIfObject(TObject *obj);
- /* IF obj <> NIL THEN obj.Free; useful for freeing an object that might sometimes be NIL. */
-
- extern pascal void FreeObject(TObject *obj);
- /* Synonym for FreeIfObject. Left in for compatibility (2.0) */
-
- extern pascal Size GetClassSizeFromID(ObjClassID classID);
- /* Given an object id, return the class's instantiation size. */
-
- extern pascal void GetClassNameFromID(ObjClassID classID, StringPtr clName);
- /* Given an object id, return the object's name. ??? add error checking ??? */
-
- extern pascal ObjClassID GetClassIDFromName(StringPtr clName);
- /* Given an object name, return its id. */
-
- extern pascal ObjClassID GetClassID(TObject *obj);
- /* Given an object, return the object's ClassID. */
-
- extern pascal ObjClassID GetSuperClassID(ObjClassID objID);
- /* returns immediate superclass of class. Returns kNilClass for TObject. If we ever get MI
- this will have to be an enumerator. */
-
- extern pascal void IDUobject(void);
- /* Writeln UObject compile date */
-
- extern pascal void InitUObject(void);
- /* Essential one time initialization for this unit */
-
- extern pascal void InspectObject(TObject *obj);
- /* Called by debugger to inspect an object. NOTE: not currently called by the "inspector" */
-
- extern pascal Boolean IsObject(void *obj);
- /* Debugging check. Returns true if obj references a real object, false if obj is NIL or a
- non-object reference. This is not an absloutely sure-fire test of objectness, but does
- validate the following: (1) is it a handle? (2) is the handle non-purgeable? (3) is the
- class ID valid? (4) is the handle size at least as large as the class size? */
-
- extern pascal Boolean IsClassIDMemberClass(ObjClassID testClass, ObjClassID superClass);
- /* tests the testClass for MEMBERship in the superclass */
-
- extern pascal Boolean IsMemberClassID(TObject *obj, ObjClassID objID);
- /* Returns true if obj references the class or a subclass of the class represented by ob
- jID. */
-
- extern pascal void OBJFail(short error);
- /* Entered due (presumably) to some object failing a test for objectness. There are two
- codes
- which result in a special message: kFailCoercion, which means that an object could not be
- coerced to a class due to not being a subclass of that class; and kFailMethNotFound, which
- means a method was called for a class, but that method is not defined for the class. Other
- codes are allowed but are not given special treatment. In qDebug mode a ProgramBreak
- preceeds the Failure. */
-
- extern pascal TObject *NewObjectByClassId(ObjClassID classID);
- /* Creates an object of the given class id */
-
- extern pascal TObject *NewObjectByClassName(StringPtr className);
- /* Creates an object of the given class name */
-
- extern pascal Boolean VerboseIsObject(void *obj);
- /* Debugging check. Indicate whether the parameter appears to really be an object and emit
- diagnostics if it is not */
-
- extern pascal void WrLblField(StringPtr fieldName, Ptr fieldAddr, short fieldType);
- /* Writes the given field in the writeln window in the form: WRITE(fieldName, '=',
-
- valueAsString).*/
- #endif
-
-